package com.xbongbong.saas.enums;

import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.saas.enums.business.*;
import lombok.Getter;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 流水记录类型
 * @author lee
 * @date 2019/5/1 17:14
 * @since v1.0
 * @version v1.0
 */
@Getter
public enum StockFilterTypeEnum {
    /**
     *
     */
    OUT_STOCK(FieldTypeEnum.REF_ID.getType(), "outstock", "出库单", XbbRefTypeEnum.OUTSTOCK.getCode(), OutstockEnum.SHEET_NO.getAttr(), OutstockEnum.SHEET_NO.getFieldType(), Arrays.asList(XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode(),XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode(),XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getCode(),XbbRefTypeEnum.WORK_ORDER_OUTSTOCK.getCode(),XbbRefTypeEnum.OTHER_OUTSTOCK.getCode())),
    IN_STOCK(FieldTypeEnum.REF_ID.getType(), "instock", "入库单", XbbRefTypeEnum.INSTOCK.getCode(), InstockEnum.SHEET_NO.getAttr(), InstockEnum.SHEET_NO.getFieldType(), Arrays.asList(XbbRefTypeEnum.PURCHASE_INSTOCK.getCode(),XbbRefTypeEnum.REFUND_INSTOCK.getCode(),XbbRefTypeEnum.PRODUCTION_INSTOCK.getCode(),XbbRefTypeEnum.RETURNED_MATERIEL_INSTOCK.getCode(),XbbRefTypeEnum.OTHER_INSTOCK.getCode())),
    COST_ADJUST(FieldTypeEnum.REF_ID.getType(), "costAdjust", "调整单", XbbRefTypeEnum.COST_ADJUST.getCode(), CostAdjustEnum.ADJUST_NO.getAttr(), CostAdjustEnum.ADJUST_NO.getFieldType(), Collections.singletonList(XbbRefTypeEnum.COST_ADJUST.getCode())),
    ORI_STOCK(FieldTypeEnum.REF_ID.getType(), "oriStock", "期初", XbbRefTypeEnum.ORI_STOCK.getCode(), OriStockEnum.ORI_STOCK_NO.getAttr(), OriStockEnum.ORI_STOCK_NO.getFieldType(), Collections.singletonList(XbbRefTypeEnum.ORI_STOCK.getCode())),
    CUSTOMER(FieldTypeEnum.BUSINESS_ID.getType(), "customer", "客户", XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), CustomerManagementEnum.NAME.getAttr(), CustomerManagementEnum.NAME.getFieldType(), Arrays.asList(XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode(), XbbRefTypeEnum.REFUND_INSTOCK.getCode(), XbbRefTypeEnum.WORK_ORDER_OUTSTOCK.getCode())),
    SUPPLIER(FieldTypeEnum.BUSINESS_ID.getType(), "supplier", "供应商", XbbRefTypeEnum.SUPPLIER.getCode(), SupplierEnum.SUPPLIER_NAME.getAttr(), SupplierEnum.SUPPLIER_NAME.getFieldType(), Arrays.asList(XbbRefTypeEnum.PURCHASE_INSTOCK.getCode(), XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode())),
    ;

    private Integer fieldType;

    private String attr;

    private String name;

    private Integer businessType;

    private String linkAttr;

    private Integer linkFieldType;

    private List<Integer> businessTypeList;

    StockFilterTypeEnum(Integer fieldType, String attr, String name, Integer businessType, String linkAttr, Integer linkFieldType, List<Integer> businessTypeList) {
        this.fieldType = fieldType;
        this.attr = attr;
        this.name = name;
        this.businessType = businessType;
        this.linkAttr = linkAttr;
        this.linkFieldType = linkFieldType;
        this.businessTypeList = businessTypeList;
    }

    public static void getMapByFieldType(Integer fieldType, Map<String, String> map) {
        for (StockFilterTypeEnum stockFilterTypeEnum : values()) {
            if (stockFilterTypeEnum.getFieldType().equals(fieldType)) {
                map.put(stockFilterTypeEnum.getAttr(), stockFilterTypeEnum.getName());
            }
        }
    }

    public static StockFilterTypeEnum getByAttr(String attr) {
        for (StockFilterTypeEnum stockFilterTypeEnum : values()) {
            if (stockFilterTypeEnum.getAttr().equals(attr)) {
                return stockFilterTypeEnum;
            }
        }
        return null;
    }
}
